package balmysundaycandy.more.low.level.mail;

import com.google.appengine.api.mail.MailServicePb.MailMessage;
import com.google.appengine.repackaged.com.google.io.protocol.ProtocolMessage;
import com.google.apphosting.api.ApiProxy;
import com.google.apphosting.api.ApiBasePb.VoidProto;

/**
 * @author marblejenka
 *
 * @param <Request>
 * @param <Response>
 */
public abstract class MailOperation<Request extends ProtocolMessage<?>, Response extends ProtocolMessage<?>> {
	private static final String packageName = "mail";

	public abstract Response call(Request request);

	public static final class SendOperation extends MailOperation<MailMessage, VoidProto> {
		@Override
		public VoidProto call(MailMessage request) {
			VoidProto response = new VoidProto();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "Send", request.toByteArray()));
			return response;
		}
	}
	
	public static final class SendToAdminsOperation extends MailOperation<MailMessage, VoidProto> {
		@Override
		public VoidProto call(MailMessage request) {
			VoidProto response = new VoidProto();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "SendToAdmins", request.toByteArray()));
			return response;
		}
	}
}
